package graduate.cslg.com.universityshopping.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import graduate.cslg.com.universityshopping.R;
import graduate.cslg.com.universityshopping.entity.ReplyBean;

public class BBSReplyAdapter extends RecyclerView.Adapter<BBSReplyAdapter.ViewHolder> {

    private Context mContext;
    public static final String REPLY_INFO = "bbs_reply_into";
    private List<ReplyBean> mReplyBeans;

    public class ViewHolder extends RecyclerView.ViewHolder {

        RelativeLayout replyItem;
        TextView userName;
        TextView replyTime;
        TextView replyContent;
        CircleImageView userImage;

        public ViewHolder(View itemView) {
            super(itemView);
            replyItem = itemView.findViewById(R.id.reply_item);
            userName = itemView.findViewById(R.id.user_name);
            replyContent = itemView.findViewById(R.id.reply_content);
            userImage = itemView.findViewById(R.id.user_head_img);
            replyTime = itemView.findViewById(R.id.reply_date);
        }
    }

    public BBSReplyAdapter(List<ReplyBean> replyBeans) {
        this.mReplyBeans = replyBeans;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_reply_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.replyItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ReplyBean bean = mReplyBeans.get(position);
        holder.userName.setText(bean.getReply_name());
        holder.replyTime.setText(bean.getReply_time());
        holder.replyContent.setText(bean.getReply_content());
    }

    @Override
    public int getItemCount() {
        return mReplyBeans.size();
    }

}
